package com.iespring.controller.admin.keyword;

import com.iespring.bean.admin.keyword.bo.KeywordCreateBO;
import com.iespring.bean.admin.keyword.pojo.Keyword;
import com.iespring.bean.admin.keyword.vo.KeywordCreateVO;
import com.iespring.bean.admin.keyword.vo.ListKeywordVO;
import com.iespring.bean.common.BasePageInfo;
import com.iespring.bean.common.BaseRespVo;
import com.iespring.service.admin.keyword.KeywordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 浩澄
 * @Date: 2022/12/29-14:46
 * @Mission: #关键词模块
 */
@RestController
@RequestMapping("admin/keyword")
public class KeywordController {

    @Autowired
    KeywordService keywordService;

    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo info , String keyword, String url){

        //是null或""或"xxx"
        ListKeywordVO listKeywordVO = keywordService.list(info,keyword,url);

        return BaseRespVo.ok(listKeywordVO);
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody KeywordCreateBO keywordCreateBO){

        KeywordCreateVO keywordCreateVO = keywordService.create(keywordCreateBO);

        return BaseRespVo.ok(keywordCreateVO);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Keyword keyword){

        Keyword keywordUpdate = keywordService.update(keyword);

        return BaseRespVo.ok(keywordUpdate);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody KeywordCreateVO keywordCreateVO){

        int code = keywordService.delete(keywordCreateVO);

        if (code == 200){
            return BaseRespVo.ok();
        }else {
            return BaseRespVo.error("删除关键词失败",621);
        }
    }

}
